{template 'public/header'}

{template 'public/comhead'}

<link rel="stylesheet" type="text/css" href="../addons/yzzc_sun/template/public/ygcsslist.css">
<ul class="nav nav-tabs">
    <span class="ygxian"></span>
    <div class="ygdangq">当前位置:</div>
    <li class="active"><a>门店结算列表</a></li>
    <li><a href="{php echo $this->createWebUrl('branchslist');}"><i class="fa fa-refresh"></i>返回门店列表</a></li>
</ul>

<div class="row ygrow">
    <div class="col-lg-12">
        <form class="form-inline" action="" method="get">
            <input type="hidden" name="c" value="site" />
            <input type="hidden" name="a" value="entry" />
            <input type="hidden" name="m" value="yzzc_sun" />
            <input type="hidden" name="do" value="order_role_income" />
            <input type="hidden" name="op" value="display" />
            <input type="hidden" name="token" value="{$_W['token']}"/>
            <div class="form-group">
                <label for="keyword">关键词</label>
                <input type="text" class="form-control" name="keywords" id="keyword" value="{$keywords}" placeholder="请输入订单号，车牌号，交车员">
            </div>
            <div class="form-group">
                <label for="store_id">个人车主</label>
                <select class="form-control" id="store_id" name="store_id" style="width: 150px">
                    <option value="">请选择个人车主</option>
                    {loop $store_list $index $item}
                    <option value="{$item['store_id']}" {if $store_id == $item['store_id'] } selected {/if}>{$item['name']}</option>
                    {/loop}
                </select>
            </div>
            <div class="form-group">
                <label for="distribution_id">经办人</label>
                <select class="form-control" id="distribution_id" name="distribution_id" style="width: 150px">
                    <option value="">请选择经办人</option>
                    {loop $distribution_list $index $item}
                    <option value="{$item['uid']}" {if $distribution_id == $item['uid'] } selected {/if}>{$item['name']}</option>
                    {/loop}
                </select>
            </div>
            <div class="form-group">
                <label>创建时间</label>
                {php echo tpl_form_field_daterange('range_time',array('start'=>date('Y-m-d H:i', $start_time),'end'=>date('Y-m-d H:i', $end_time)),true);}
            </div>
            <input type="submit"  name="submit"  value="搜索" class="btn btn-default">
        </form>
    </div>
</div>

<div class="row ygrow">
    <div class='col-lg-12'>
<!--        <div class="ygdangq" style="margin-left:0">统计:</div>-->
        <li><p style="margin-top: 6px;">总金额：<label style="color: red">{$total_money}</label></p></li>
        <li><p style="margin-top: 6px;">门店总收益：<label style="color: red">{$branch_total}</label></p></li>
        <li><p style="margin-top: 6px;">车主总收益：<label style="color: red">{$store_total}</label></p></li>
        <li><p style="margin-top: 6px;">销售总收益：<label style="color: red">{$distribution_total}</label></p></li>
<!--        <li><p style="margin-top: 6px;">交车员总收益：<label style="color: red">{$shuttle_total}</label></p></li>-->
<!--        {if $start_time}-->
<!--        <li><p style="margin-top: 6px;">{php echo date('Y-m-d H:i', $start_time)} 至 {php echo date('Y-m-d H:i', $end_time)} 结算总金额：<label style="color: red">{$search_total}</label></p></li>-->
<!--        {/if}-->
    </div>
</div>
<!--<div class="row ygrow">
    <div class='col-lg-12'>
        <div class="ygdangq" style="margin-left:0">批量操作:</div>
        <a id="month_income" onclick="branch_income('all')"><button class="btn btn-sm store-blue">全部结算</button></a>
        <a id="other_income" onclick="branch_income('search')"><button class="btn btn-sm store-blue">时间范围结算</button></a>
    </div>
</div>-->
<div class="main ">

    <div class="panel panel-default">
        <div class="panel-heading">
            收益列表
        </div>

        <div class="panel-body" style="padding: 0px 15px;">
            <div class="row" id="accordion">
                <table class="yg5_tabel col-md-12">
                    <tr class="yg5_tr1">
                        <td  class="store_td1 col-md-1">车辆名称</td>
                        <td  class="store_td1 col-md-1">车牌号</td>
                        <td  class="store_td1 col-md-1">订单总租金</td>
                        <td  class="store_td1 col-md-1">送车人</td>
                        <td  class="store_td1 col-md-1">还车人</td>
                        <td  class="store_td1 col-md-1">门店</td>
                        <td  class="store_td1 col-md-1">门店收益</td>
                        <td  class="store_td1 col-md-1">个人车主</td>
                        <td  class="store_td1 col-md-1">车主收益</td>
                        <td  class="store_td1 col-md-1">经办人</td>
                        <td  class="store_td1 col-md-1">经办人收益</td>
                        <td class="col-md-2">创建时间</td>
                    </tr>

                    {loop $info $key $item}
                    <tbody>
                    <tr class="yg5_tr2" >
                        <td>{$item['car_name']}</td>
                        <td>{$item['carnum']}</td>
                        <td>{$item['total_money']}</td>
                        <td>{$item['shuttle_name']}
                            (
                            {if $item['gettype']==1}
                            门店
                            {else}
                            上门
                            {/if}
                            )
                        </td>
                        <td>
                            {if $item['reclaim_shuttle_name']}
                            {$item['reclaim_shuttle_name']}(
                            {if $item['is_onsite']==1}
                            上门
                            {else}
                            门店
                            {/if}
                            )
                            {/if}
                        </td>
                        <td>{$item['branch_name']}</td>
                        <td>{$item['branch_total']}</td>
                        <td>{$item['store_name']}</td>
                        <td>{$item['store_total']}</td>

                        <td>{$item['distribution_name']}</td>
                        <td>{$item['distribution_order_total']}</td>
<!--                        <td>-->
<!--                            {if $item['type']==1}-->
<!--                            <span class="label store-blue">平台自营</span>-->
<!--                            {elseif $item['type']==2}-->
<!--                            <span class="label store-green">商家入驻</span>-->
<!--                            {elseif $item['type']==3}-->
<!--                            <span class="label store-yellow">个人商户</span>-->
<!--                            {/if}-->
<!--                        </td>-->
                        <td>{$item['createtime']}</td>
<!--                        <td>-->
<!--                            <a href="javascript:;" class="storespan btn btn-xs" onclick="del({$item['id']})">-->
<!--                                <span class="fa fa-trash-o"></span><span class="bianji">删除<span class="arrowdown"></span></span>-->
<!--                            </a>-->
<!--                        </td>-->
                    </tr>
                    </tbody>
                    {/loop}
                    {if empty($info)}
                    <tr class="yg5_tr2">
                        <td colspan="8">
                            暂无收益信息
                        </td>
                    </tr>
                    {/if}
                </table>
            </div>
        </div>

    </div>
    </form>
</div>
<script type="text/javascript">
    $(function(){
        $("#frame-2").show();
        $("#yframe-2").addClass("wyactive");
    })

    function branch_income(type){
        var start_time = $('input[name="range_time[start]"]').val()
        var end_time = $('input[name="range_time[end]"]').val()
        console.log(end_time,start_time)
        if (type === 'search' && (!start_time|| !end_time)){
            alert('请选择结算日期范围');return
        }
        var confirm_msg = '确定结算'+start_time+'至'+end_time + '?';
        if (type === 'all'){
            confirm_msg = '确定结算门店下面全部收益？';
        }
        var ret = confirm(confirm_msg)
        if (ret==true){
            var branch_id = "{$branch_id}";
            $.ajax({
                type:"POST",
                url:"{php echo $this->createWebUrl('branch_store_income',array('op'=>branch_income))}",
                dataType:"JSON",
                data:{branch_id:branch_id,type:type,start_time:start_time,end_time:end_time},
                success:function(res){
                    if(res.type === 'success') {
                        alert('结算成功');
                        location.reload();
                    }else{
                        alert(res.message);
                    }
                }
            })
        }
    }
    $('#month_income').click(function () {

    })
</script>